package my.netty.channel;

import my.netty.concurrent.SingleThreadEventExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ThreadFactory;

public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop {

    private static final Logger log = LoggerFactory.getLogger(SingleThreadEventLoop.class);

    public SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory) {
        super(parent, threadFactory);
    }

    public void register(Channel channel) {
        if (inEventLoop(Thread.currentThread())) {
            register0(channel);
        } else {
            execute(() -> register0(channel));
        }
    }

    protected abstract void register0(Channel channel);

}
